package com.seal.tsms.exam.controller;

import com.seal.tsms.base.controller.BaseController;
import com.seal.tsms.base.service.BaseService;
import com.seal.tsms.exam.entity.Teacher;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap;

import java.util.List;

/**
 * Created by zhangfan on 2016/6/6.
 */
@Controller
@RequestMapping("/teacher")
public class TeacherController extends BaseController<Teacher,String>{
    @Override
    @Autowired
    @Qualifier("teacherServiceImpl")
    public void setSelfService(BaseService<Teacher,String>selfService){super.setSelfService(selfService);}
        @RequestMapping(value = "/save",method = RequestMethod.GET)
        public String create() {return "exam/teacher/add";}
        @RequestMapping(value = "/save",method = RequestMethod.POST)
        public String save(Teacher teacher, RedirectAttributesModelMap model){
        getSelfService().save(teacher);
        model.addFlashAttribute("msg","成功保存一条数据");
        return "redirect:list.action";

    }
        @RequestMapping(value = "/list")
        public String list(ModelMap model){
            List<Teacher>teachers=(List<Teacher>)getSelfService().list(DetachedCriteria.forClass(Teacher.class),null);
            model.addAttribute("teachers",teachers);
            return "exam/teacher/list";
    }
    @RequestMapping(value = "teacherListAjax")
    @ResponseBody
    public List<Teacher> ajaxList(){
        return (List<Teacher>) getSelfService().list(DetachedCriteria.forClass(Teacher.class),null);
    }
}
